package com.jrx.anytxn.investor.service;

import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.investor.bean.InvestorCastAccountBean;
import com.jrx.anytxn.investor.bean.InvestorCastAccountTransactionBean;
import com.jrx.anytxn.investor.dto.loan.LoanReq;
import com.jrx.anytxn.investor.entity.*;
import com.jrx.anytxn.param.entity.PrFundFactor;
import com.jrx.anytxn.param.entity.PrInvestorPenaltyRate;
import com.jrx.anytxn.transaction.bean.DelqParamBean;
import com.jrx.anytxn.transaction.entity.AmLoanMainInfo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 联合贷账户Service理接口
 *
 * @author liuyang
 * @date 2020-05-18
 */
public interface IInvestorAccountService {

    /**
     * 构建贷款信息
     *
     * @param loanMainInfo 对客订单
     * @param loanReq 放款请求信息
     * @param fundFactor 出资方信息
     * @param loanAmount 贷款金额
     * @return AmLoanMainInvestorInfo 贷款信息
     * @throws TxnException
     * @author liuyang
     * @date 2020-05-18
     */
    AmLoanMainInvestorInfo buildAmLoanMainInvestorInfo(AmLoanMainInfo loanMainInfo, LoanReq loanReq, PrFundFactor fundFactor, BigDecimal loanAmount) throws TxnException;

    /**
     * 构建贷款账户
     *
     * @param loanMainInvestorInfo 贷款信息
     * @return AmLoanAccountInvestorInfo 贷款账户
     * @throws TxnBizException
     * @author liuyang
     * @date 2020-05-19
     */
    AmLoanAccountInvestorInfo buildAmLoanAccountInvestorInfo(AmLoanMainInvestorInfo loanMainInvestorInfo) throws TxnBizException;

    /**
     * 根据还款计划更新贷款信息和贷款账户信息
     *
     * @param loanMainInvestorInfo 贷款信息
     * @param loanAccountInvestorInfo 贷款账户
     * @param repaymentPlanInvestorInfos 还款计划
     * @throws TxnBizException
     * @author liuyang
     * @date 2020-05-20
     */
    void updateLoanMainAndAccountInvestorInfo(AmLoanMainInvestorInfo loanMainInvestorInfo, AmLoanAccountInvestorInfo loanAccountInvestorInfo,List<AmRepaymentPlanInvestorInfo> repaymentPlanInvestorInfos) throws TxnException;

    /**
     * 抛账  抛分期费用账户
     *
     * @param loanMainInvestorInfo 贷款信息
     * @param loanAccountInvestorInfo 贷款账户
     * @param repaymentPlanInvestorInfo 还款计划
     * @param businessDate 业务日期
     * @return InvestorCastAccountTransactionBean 费用交易账户
     * @throws TxnBizException
     * @author liuyang
     * @date 2020-05-20
     */
    InvestorCastAccountTransactionBean castInstallmentFeeAccount(AmLoanMainInvestorInfo loanMainInvestorInfo, AmLoanAccountInvestorInfo loanAccountInvestorInfo, AmRepaymentPlanInvestorInfo repaymentPlanInvestorInfo, Date businessDate) throws TxnException;

    /**
     * 抛账  抛出利息累计账户
     *
     * @param repaymentPlanInvestorInfo 还款计划
     * @param accountMainInvestorInfo 交易账户信息
     * @param loanAccountInvestorInfo 订单账户
     * @param loanMainInvestorInfo 订单信息
     * @param accrualBaseAmount 计息金额
     * @param delqParamBean 延滞参数
     * @return AmInterestAccrualInvestorInfo 累计账户信息
     * @throws TxnException
     * @author liuyang
     * @date 2020-05-21
     */
    AmInterestAccrualInvestorInfo castInterestAccrualAccount(AmRepaymentPlanInvestorInfo repaymentPlanInvestorInfo, AmAccountMainInvestorInfo accountMainInvestorInfo, AmLoanAccountInvestorInfo loanAccountInvestorInfo, AmLoanMainInvestorInfo loanMainInvestorInfo, BigDecimal accrualBaseAmount, DelqParamBean delqParamBean) throws TxnException;

    /**
     * 生成账户id
     *
     * @param accountType 账户类型
     * @param tenantId 租户id
     * @param customerId 客户id
     * @return String 账户id
     * @author liuyang
     * @date 2020-05-20
     */
    String getAccountId(String accountType, String tenantId, String customerId);

    /**
     * 获取订单计划剩余本金金额
     *
     * @param repaymentPlanInfoList 还款计划
     * @param billingTenor 第几期
     * @return BigDecimal 剩余本金
     * @author liuyang
     * @date 2020-05-20
     */
    BigDecimal getPlanPrinBalance(List<AmRepaymentPlanInvestorInfo> repaymentPlanInfoList, Integer billingTenor);


    /**
     * 抛账   抛当期本金、费用、利息累计
     *
     * @param loanMainInvestorInfo 订单信息
     * @param loanAccountInvestorInfo 订单账户
     * @param repaymentPlanInfoList 还款计划
     * @param businessDate 业务日期
     * @param isValid 是否需要验证今天是否是抛账日
     * @return InvestorCastAccountBean 抛账更新的信息
     * @throws TxnException
     * @author liuyang
     * @date 2020-05-21
     */
    InvestorCastAccountBean castTxnAccount(AmLoanMainInvestorInfo loanMainInvestorInfo, AmLoanAccountInvestorInfo loanAccountInvestorInfo, List<AmRepaymentPlanInvestorInfo> repaymentPlanInfoList, Date businessDate, Boolean isValid) throws TxnException;

    /**
     * 得到当期还款计划明细
     *
     * @param tenor 第几期
     * @param repaymentPlanInfoList 还款计划列表
     * @return AmRepaymentPlanInvestorInfo 还款计划
     * @author liuyang
     * @date 2020-05-21
     */
    AmRepaymentPlanInvestorInfo getRepaymentPlanInfo(Integer tenor, List<AmRepaymentPlanInvestorInfo> repaymentPlanInfoList);

    /**
     * 抛账  抛出本金账户
     *
     * @param loanMainInvestorInfo 订单信息
     * @param loanAccountInvestorInfo 订单账户
     * @param repaymentPlanInfo 还款计划
     * @param delqParamBean 延滞参数
     * @param businessDate 业务日期
     * @return InvestorCastAccountTransactionBean 账户交易信息
     * @throws TxnException
     * @author liuyang
     * @date 2020-05-21
     */
    InvestorCastAccountTransactionBean castPrincipalAccount(AmLoanMainInvestorInfo loanMainInvestorInfo, AmLoanAccountInvestorInfo loanAccountInvestorInfo, AmRepaymentPlanInvestorInfo repaymentPlanInfo, DelqParamBean delqParamBean, Date businessDate) throws TxnException;

    /**
     * 累计账户抛账  抛出交易账户
     *
     * @param loanMainInvestorInfo
     * @param loanAccountInvestorInfo
     * @param amInterestAccrualInvestorInfo
     * @param businessDate
     * @return
     * @throws TxnBizException
     */
    InvestorCastAccountTransactionBean castInterestAccount(AmLoanMainInvestorInfo loanMainInvestorInfo, AmLoanAccountInvestorInfo loanAccountInvestorInfo, AmInterestAccrualInvestorInfo amInterestAccrualInvestorInfo, Date businessDate) throws TxnException;

    /**
     * 生成延滞交易账户
     *
     * @param amLoanMainInfo 订单信息
     * @param amRepaymentPlanInfo 还款计划
     * @param businessdate 业务日期
     * @param delqDays 逾期天数
     * @return AmDelinquencyInvestorInfo 延滞交易账户
     * @throws TxnBizException
     * @author liuyang
     * @date 2020-05-21
     */
    AmDelinquencyInvestorInfo generateDelinquencyInfo(AmLoanMainInvestorInfo amLoanMainInfo, AmRepaymentPlanInvestorInfo amRepaymentPlanInfo, Date businessdate, Integer delqDays) throws TxnBizException;

    /**
     * 抛出罚息、复利累计账户
     *
     * @param amRepaymentPlanInfo 还款计划
     * @param amLoanMainInfo 订单信息
     * @param amLoanAccountInfo 订单账户
     * @param penaltyRateTable 罚息利率参数
     * @param delqParamBean 延滞参数
     * @param intrBeginDate 起息日
     * @return List<AmInterestAccrualInvestorInfo> 罚息，复利累计账户
     * @throws TxnBizException
     * @author liuyang
     * @date 2020-05-26
     */
    List<AmInterestAccrualInvestorInfo> castPenAndComAccrualAccount(AmRepaymentPlanInvestorInfo amRepaymentPlanInfo, AmLoanMainInvestorInfo amLoanMainInfo,
                                                                    AmLoanAccountInvestorInfo amLoanAccountInfo, PrInvestorPenaltyRate penaltyRateTable,
                                                                    DelqParamBean delqParamBean, Date intrBeginDate) throws TxnBizException;
    /**
     * 生成轧差费用交易账户
     * @param offSetLoanMainInvestorInfo
     * @param offsetAmt
     * @param businessDate
     * @return
     */
    InvestorCastAccountTransactionBean castOffsetFeeAccount(AmLoanMainInvestorInfo offSetLoanMainInvestorInfo, AmLoanAccountInvestorInfo offsetLoanAccountInvestorInfo,BigDecimal offsetAmt, int tenor,String feeTxnCode,Date businessDate) throws TxnException;



    /**
     * 生成提前还款提前结清费用交易账户
     * @param amLoanMainInfo
     * @param amLoanAccountInfo
     * @param feeTxnCode
     * @param fee
     * @param businessDate
     * @param liabilityFlag
     * @return
     * @throws TxnException
     */
    InvestorCastAccountTransactionBean castPaymentFeeAccount(AmLoanMainInvestorInfo amLoanMainInfo, AmLoanAccountInvestorInfo amLoanAccountInfo, String feeTxnCode,
                                                             BigDecimal fee, Date businessDate,String liabilityFlag) throws TxnException;

    /**
     * 根据还款计划生成利息交易账户
     * @param amLoanMainInfo
     * @param amLoanAccountInfo
     * @param amRepaymentPlanInfo
     * @param delqParamBean
     * @param businessDate
     * @return
     * @throws TxnException
     */
    InvestorCastAccountTransactionBean castIntrAccount(AmLoanMainInvestorInfo amLoanMainInfo, AmLoanAccountInvestorInfo amLoanAccountInfo,
                                                       AmRepaymentPlanInvestorInfo amRepaymentPlanInfo, DelqParamBean delqParamBean, Date businessDate) throws TxnException;

    /**
     * 根据原累计账户生成表外累计账户
     * @param accuAcct
     * @param bussinessDate
     * @return
     * @throws TxnBizException
     */
    AmInterestAccrualInvestorInfo castNonInterestAccrualAccount(AmInterestAccrualInvestorInfo accuAcct, Date bussinessDate) throws TxnBizException;
}
